'use strict';
angular.module('inventory.recordDetailQualitySelectSingle', ['app.services'])
	.controller('recordDetailQualitySelectSingleCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title', f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {

		var Model = this;


		Model.gridRowClick = function(event){
			
			
		}

		Model.gridRowDblClick = function(event){
			Model.ok();
		}
		
		
		var options = {};
		options.concept = 'StorageRecordDetail';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.reader = '/inventory/recordDetailQuery/list/query';
		options.writer = '';
		options.deleter = '';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = false;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.pathRelation = '';
//		options.master = {"data":"$scope.dataMaster","relation":"fMasterID"};
//		options.masterData = $scope.dataMaster;
//		options.slaveDatas = null;
		options.directDeleteMode = false;
		options.orderBy = 'recordNo,serialNo ASC';
		options.limit = 10;
		
		$scope.dataList = new BizData(options);

		//监视对象中的所有变动
//		$scope.dataList.deregRows = $scope.$watch('dataList.rows',$scope.dataList.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		////////////////////启动执行开始///////////////////////////////////////////////////
		//接收调用的参数
//		Model.params = $rootScope.$stateParams;  
		

		////////////////////启动执行结束///////////////////////////////////////////////////
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
        	Model.title = title;  
        	Model.params = params;  

    		//设置过滤条件
    		$scope.dataList.filter = "StorageRecordDetail.enterpriseNo like '%"+ Model.params.id +"%'"
    		+" AND StorageRecordDetail.status='open' "
    		+" AND StorageRecordDetail.state='confirm' "
    		+" AND StorageRecordDetail.audit='active' "
    		+" AND StorageRecordDetail.qualityStatus=1 "; //待验
    		
    		var filter;
    		if(Model.params.billType=='GYZY'){
    			//包含工艺入库
        		filter = " AND (StorageRecordDetail.billType='"+Model.params.billType+"' OR (StorageRecordDetail.billType='GYRK' AND StorageRecordDetail.direction=1)) ";
    		}else{
        		filter = " AND StorageRecordDetail.billType='"+Model.params.billType+"' ";
    		}
    		
    		$scope.dataList.filter = $scope.dataList.filter + filter;

    		//刷新数据
    	    $scope.dataList.refreshData();
        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	var sourceRow = $scope.dataList.rows[$scope.dataList.currentIndex];
	    	var row = {};
			//循环行中的列，取出列的值，装配成简单的行
			for(var obj in sourceRow){
				if(obj!='$$hashKey' && obj!='userdata'){
					row[obj] = sourceRow[obj].value;
				}
			}
	    	data.push(row);
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////

	    return Model;
	    
	}	
	
